package org.wxd.bi.api.struct;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.wxd.lang.save.ObjectBase;
import org.wxd.net.web.template.HtmlStyle;

import java.io.Serializable;

/**
 * 字段映射
 *
 * @author: Troy.Chen(無心道, 15388152619)
 * @version: 2021-09-30 14:36
 **/
@Getter
@Setter
@Accessors(chain = true)
public class PushColumn extends ObjectBase implements Serializable, Comparable<PushColumn>, Cloneable {

    private static final long serialVersionUID = 1L;
    /**
     * 唯一id
     */
    public static final PushColumn ID = new PushColumn()
            .setName("id")
            .setPk(true)
            .setComment("编号")
            .setTypeStr(long.class.getSimpleName())
            .setShowIndex(1);

    /**
     * 保存时间
     */
    public static final PushColumn SAVE_TIME = new PushColumn()
            .setName("saveTime")
            .setComment("保存时间")
            .setTypeStr(long.class.getSimpleName())
            .setDbIndex(true)
            .setShowIndex(2);

    /**
     * 创建时间
     */
    public static final PushColumn CREATE_TIME = new PushColumn()
            .setName("createTime")
            .setComment("创建时间")
            .setTypeStr(long.class.getSimpleName())
            .setDbIndex(true)
            .setShowIndex(3);

    /**
     * 扩展信息
     */
    public static final PushColumn EXPAND = new PushColumn()
            .setName("expand")
            .setComment("扩展信息")
            .setTypeStr(String.class.getSimpleName())
            .setShowIndex(1000);

    private String name;
    /**
     * 主键列
     */
    private boolean pk;
    /**
     * 类型
     */
    private String typeStr;
    /**
     * 备注
     */
    private String comment;
    private boolean dbIndex;
    /*页面控件宽度*/
    private HtmlStyle htmlStyle = new HtmlStyle();
    private int showIndex = 999;

    public PushColumn() {
    }

    public PushColumn(String name, String typeStr, String comment) {
        this(name, typeStr, comment, false);
    }

    public PushColumn(String name, String typeStr, String comment, boolean dbIndex) {
        this.name = name;
        this.typeStr = typeStr;
        this.comment = comment;
        this.dbIndex = dbIndex;
    }

    public PushColumn(String name, String typeStr, String comment, boolean dbIndex, int showIndex) {
        this.name = name;
        this.typeStr = typeStr;
        this.comment = comment;
        this.dbIndex = dbIndex;
        this.showIndex = showIndex;
    }

    @Override
    public PushColumn clone() throws CloneNotSupportedException {
        return (PushColumn) super.clone();
    }

    @Override
    public int compareTo(PushColumn o) {
        return Integer.compare(this.getShowIndex(), o.getShowIndex());
    }

}
